<?php 
/* 
Template Name: Full manager
*/
?>
<?php get_header(); ?>
<?php 
 $base_url=get_bloginfo('template_directory'); 
?>
<script type="text/javascript">


  $('.btn_del').click(function(){

    //alert($(this).val());
    alert('aaaaaa');
    });

  function confirmDelete()
  {
     var r=confirm("Bạn có muốn xóa người này không ?");
     //var xoa_may_del = $('#xoa_may_del').val();
    
      if (r==true)
      {   //url: "<?php bloginfo('url');?>"+'/delete-user',
         // data: {xoa_may_del:idmay},
          //var xoa_may_del = $("#xoa_may_del").val();
          // xoadel
         
           var idmay = $(this).attr("idmay");
           alert(idmay);
            return 0;


           alert('hpoang phuc');
           $.ajax({
            type: "POST", 
            url: "<?php bloginfo('url');?>"+'/xoa-may',
            data: {idmay:idmay},
            success: function(){ 
             alert('xoa thanh cong');
              //$('#xoadel').html(msg);
            },error: function (){
                alert('Có lỗi xảy ra');
              }
          });
          
      }
      else
       {
        return false;
      //user pressed cancel. Do nothing
          }
   }

</script>

<?php 
 
if ( ! current_user_can( 'list_users' ) ) 
    {
      wp_die( __( 'bạn không có quyền truy cập trang này! ' ) );

            global $id_sai_email;$status_pass;
            global $current_user;
            get_currentuserinfo();
    }//if ( ! current_user_can( 'list_users' ) ) 
    else { ?>
<div id="content_nano_two" class="clearfix">
  <!--<button  style='color: #2a789e;font-weight:bold;' class="button action" id='them_moi_nhieu'>Thêm người phân quyền</button>
-->
<?php 
   echo 'phanquyen : '.$_POST['phanquyen'];
?>
  <div id="dialog-form-them-quan-tri" title="Chọn thêm người phân quyền">
        <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    ?>         
             <form action='#' method="get" >
               <table class="wp-list-table widefat fixed users" cellspacing="0">
                    <thead>
                     <tr>
                       <th scope="col" id="cb"  style=""> </th>
                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                       <th scope="col" id="email"style=""></th>
                     </tr>
                    </thead>
                    

                     <tbody id="the-list" data-wp-lists="list:user">
        <?php $rows = $wpdb->get_results($query_user);
             foreach($rows as $post)
             {
         ?>
              <tr id="user-<?php $post->ID; ?>" class="alternate">
                   <th scope="row" class="check-column">
                   </th>
                     <td class="username column-username">
                       <strong><?php echo $post->user_nicename;?></strong>
                    </td>
                    <td class="name column-name"><?php echo $post->display_name;?> </td>
                    <td class="email column-email">
                       <div style="display: inline-block;width: 200px;padding-top: 8px;">
                          <form><fieldset></fieldset></form>
                      <div style='float:left;'>
                          <form action='<?php bloginfo('url');?>/delete-user' method='POST'>
                             <fieldset>
                              <input type="hidden" name="xoa_user" id="xoa_user" value='<?php echo $post->ID; ?>' />
                              <input type="checkbox" name="xoa_<?php echo $post->ID;?>" id="xoa_<?php echo $post->ID;?>" value='<?php echo $post->ID;?>'/>
                            </fieldset>
                          </form>
                      </div><!-- style='float:left;' -->
                      </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                    </td>
                                                   
                </tr><!-- id="user-xyz" class="alternate" -->
        <?php } // end foreach($rows as $post) ?>

         </tbody>
                </table>
        </form>

</div><!-- id="dialog-form-them-quan-tri" title="Chọn thêm người phân quyền" -->
<div style='margin:20px;'></div>

<div id="tabs">
  <ul>
    <li><a href="#tabs-1" style='font-size: 13px;color: #2a789e;width: 134px;'>Người quản li</a></li>
    <li><a href="#tabs-2"style='font-size: 13px;color: #2a789e;width: 134px;' >Người dùng</a></li>
  </ul>
  <div id="tabs-1">
    <h2 style="margin: 3px;font-size: 19px;color: #2a789e;text-align: left;font-weight: bold;">Người quản li</h2>
    <button class="button action"  id="them-quan-tri" style='padding: 3px;margin: 3px;'>Chọn người quản lí</button>
    
  <?php 
    $sql = "SELECT * FROM wp_user_wp_may
            INNER JOIN wp_users
                        ON wp_users.ID = wp_user_wp_may.ID
                        WHERE id_may LIKE '".$_POST['phanquyen']."';";  
                        //WHERE id_may LIKE '".$_POST['phanquyen']."%';";  
     $row = $wpdb->get_results($sql);
  ?>  
    <p>         
           <form action='#' method="get" >
             <table class="wp-list-table widefat fixed users" cellspacing="0">
                  <thead>
                   <tr>
                     <th scope="col" id="cb"  style=""> </th>
                     <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                     <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                     <th scope="col" id="email"style=""></th>
                   </tr>
                  </thead>
                  

                   <tbody id="the-list" data-wp-lists="list:user">
      <?php 
       foreach($row as $key=>$value)
       {
          var_dump($value);//break;
       ?>
            <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                 <th scope="row" class="check-column">
                   <label class="screen-reader-text" for="cb-select-1"></label>
                 </th>
                   <td class="username column-username">
                     <strong><?php echo $value->user_login;?></strong>
                  </td>
                  <td class="name column-name"><?php echo $value->display_name;?> </td>
                  <td class="email column-email">
                     <div style="display: inline-block;width: 200px;padding-top: 8px;">
                        <form><fieldset></fieldset></form>
                    <div style='float:left;'>
                        <form>
                           <fieldset>
                            <input type="hidden" name="id_may" id="id_may" value='<?php echo $value->ID;?>' />
                            <input  class="btn_del" type="button"  value="<?php echo $value->ID; ?>"  />
                          </fieldset>
                        </form>
                    </div><!-- style='float:left;' -->
                    </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                  </td>
                                                 
              </tr><!-- id="user-xyz" class="alternate" -->
  <?php             
      }// foreach($row as $key=>$value)
  ?>
       </tbody>
              </table>
      </form>

    </p>

  </div><!-- d="tabs-1" -->

  <div id="tabs-2">
    <h2 style="margin: 3px;font-size: 19px;color: #2a789e;text-align: left;font-weight: bold;">Người dùng</h2>
    <button class="button action"  id="them-nguoi-dung" style='padding: 3px;margin: 3px;'>Chọn người dùng</button>
    <p>
      <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>            
         <form action='#' method="get" >
           <table class="wp-list-table widefat fixed users" cellspacing="0">
                <thead>
                 <tr>
                   <th scope="col" id="cb"  style=""> </th>
                   <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                   <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                   <th scope="col" id="email"style=""></th>
                 </tr>
                </thead>
                

                 <tbody id="the-list" data-wp-lists="list:user">
    <?php $rows = $wpdb->get_results($query_user);
         foreach($rows as $post)
         {
     ?>
          <tr id="user-<?php $post->ID; ?>" class="alternate">
               <th scope="row" class="check-column">
                 <label class="screen-reader-text" for="cb-select-1"></label>
               </th>
                 <td class="username column-username">
                   <strong><?php echo $post->user_nicename;?></strong>
                </td>
                <td class="name column-name"><?php echo $post->display_name;?> </td>
                <td class="email column-email">
                   <div style="display: inline-block;width: 200px;padding-top: 8px;">
                      <form><fieldset></fieldset></form>
                      <!--
                      <div style='float:left;'>
                         <form action='<?php bloginfo('url');?>/edit-user' method='POST'>
                            <fieldset>
                            <input type="hidden" name="sua_edit" id="sua_edit" value='<?php echo $post->ID; ?>'>
                             <input type="submit" name="sua_<?php echo $post->ID;?>" id="sua_<?php echo $post->ID;?>" value='thêm'/>
                            </fieldset>
                        </form>
                     </div><!-- style='float:left;' -->
                  <div style='float:left;'>
                      <form action='<?php bloginfo('url');?>/delete-user' method='POST'>
                         <fieldset>
                          <input type="hidden" name="xoa_user" id="xoa_user" value='<?php echo $post->ID; ?>' />
                          <input type="submit" name="xoa_<?php echo $post->ID;?>" id="xoa_<?php echo $post->ID;?>" value='Xóa'/>
                        </fieldset>
                      </form>
                  </div><!-- style='float:left;' -->
                  </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                </td>
                                               
            </tr><!-- id="user-xyz" class="alternate" -->
    <?php } // end foreach($rows as $post) ?>

     </tbody>
            </table>
    </form>

    </p>
  </div><!-- id="tabs-2" -->
  
</div><!-- id="tabs" -->


<div id="dialog-form-them-nguoi-dung" title="Chọn thêm người phân quyền">
        <?php 
     $query_user = "SELECT ID,user_nicename,display_name,user_email,user_registered FROM $wpdb->users" ;
    // WHERE post_type='post'";
    ?>         
             <form action='#' method="get" >
               <table class="wp-list-table widefat fixed users" cellspacing="0">
                    <thead>
                     <tr>
                       <th scope="col" id="cb"  style=""> </th>
                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                       <th scope="col" id="email"style=""></th>
                     </tr>
                    </thead>
                    

                     <tbody id="the-list" data-wp-lists="list:user">
        <?php $rows = $wpdb->get_results($query_user);
             foreach($rows as $post)
             {
         ?>
              <tr id="user-<?php $post->ID; ?>" class="alternate">
                   <th scope="row" class="check-column">
                   </th>
                     <td class="username column-username">
                       <strong><?php echo $post->user_nicename;?></strong>
                    </td>
                    <td class="name column-name"><?php echo $post->display_name;?> </td>
                    <td class="email column-email">
                       <div style="display: inline-block;width: 200px;padding-top: 8px;">
                          <form><fieldset></fieldset></form>
                      <div style='float:left;'>
                          <form action='<?php bloginfo('url');?>/delete-user' method='POST'>
                             <fieldset>
                              <input type="hidden" name="xoa_user" id="xoa_user" value='<?php echo $post->ID; ?>' />
                              <input type="checkbox" name="xoa_<?php echo $post->ID;?>" id="xoa_<?php echo $post->ID;?>" value='<?php echo $post->ID;?>'/>
                            </fieldset>
                          </form>
                      </div><!-- style='float:left;' -->
                      </div><!-- style="display: inline-block;width: 200px;padding-top: 8px;"> -->
                    </td>
                                                   
                </tr><!-- id="user-xyz" class="alternate" -->
        <?php } // end foreach($rows as $post) ?>

         </tbody>
                </table>
        </form>

    </div><!-- id="dialog-form-them-nguoi-dung"-->
           

</div><!-- id="content_nano_two" -->

<?php } //elseif ( ! current_user_can( 'list_users' ) )  ?>
    
<?php get_footer(); ?>